package com.qd.common.sys.domain.entity.article;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.DeleteGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.qd.common.sys.domain.entity.upload.FileUploadDTO;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 内容发布
 *
 * @author sjk
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class ArticleDTO extends BaseQuery {

    @ExcelIgnore
    @JsonIgnore
    private static final String EXCEL_TITLE ="内容发布";
    /**
     * 主键
     */
    @ExcelProperty(value = {EXCEL_TITLE, "文章标识"})
    @NotBlank(message = "文章标识不能为空", groups = {DeleteGroup.class, UpdateGroup.class})
    @Size(max = 50, message = "文章标识长度不能超过{max}位", groups = {DeleteGroup.class, UpdateGroup.class})
    private String articleId;
    /**
     * 标题
     */
    @ExcelProperty(value = {EXCEL_TITLE,"标题"})
    @NotBlank(message = "标题不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "标题长度不能超过{max}位", groups = DefaultGroup.class)
    private String title;
    /**
     * 内容
     */
    @NotBlank(message = "内容不能为空", groups = DefaultGroup.class)
    private String content;
    /**
     * 创建时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"创建时间"})
    private LocalDateTime createTime;
    /**
     * 发表时间
     */
    @ExcelProperty(value = {EXCEL_TITLE,"发表时间"})
    @NotNull(message = "发表时间不能为空", groups = DefaultGroup.class)
    private LocalDate reportTime;
    /**
     * 概述
     */
    @ExcelProperty(value = {EXCEL_TITLE,"概述"})
    @Size(max = 150, message = "概述长度不能超过{max}位", groups = DefaultGroup.class)
    private String summary;
    /**
     * 点击数
     */
    @ExcelProperty(value = {EXCEL_TITLE,"点击数"})
    private long hintCount;
    /**
     * 机构ID
     */
    @ExcelProperty(value = {EXCEL_TITLE,"机构ID"})
    @Size(max = 50, message = "机构ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String orgId;
    /**
     * 机构显示名称
     */
    private String orgIdDisplay;
    /**
     * 创建人
     */
    @ExcelProperty(value = {EXCEL_TITLE,"创建人"})
    @Size(max = 50, message = "创建人长度不能超过{max}位", groups = DefaultGroup.class)
    private String personId;
    /**
     * 创建人显示名称
     */
    private String personIdDisplay;
    /**
     * 题材分类
     */
    @ExcelProperty(value = {EXCEL_TITLE,"题材分类"})
    @NotBlank(message = "题材分类不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "题材分类长度不能超过{max}位", groups = DefaultGroup.class)
    private String articleType;
    /**
     * 题材分类显示名称
     */
    private String articleTypeDisplay;
    /**
     * 是否发布
     */
    @ExcelProperty(value = {EXCEL_TITLE,"是否发布"})
    @NotBlank(message = "是否发布不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "是否发布长度不能超过{max}位", groups = DefaultGroup.class)
    private String isPublish;
    /**
     * 是否发布显示名称
     */
    private String isPublishDisplay;
    /**
     * 附件,显示使用
     */
    private List<ArticleFileDTO> fileList;
    /**
     * 附件，添加和更新使用
     */
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @Valid
    private List<FileUploadDTO> files;
    /**
     * type = 0表示列表信息
     * type = 1表示个人用户查看列表
     */
    @JsonProperty(access = JsonProperty.Access.READ_ONLY)
    private int type=0;

    @Override
    public void freeData() {
        this.articleId = null;
        this.title = null;
        this.createTime = null;
        this.reportTime = null;
        this.summary = null;
        this.orgId = null;
        this.orgIdDisplay = null;
        this.personId = null;
        this.personIdDisplay = null;
        this.articleType = null;
        this.articleTypeDisplay = null;
        this.isPublish = null;
        this.isPublishDisplay = null;
        this.content = null;
        if(null != fileList){
            fileList.clear();
        }
        if(null != files){
            this.files = null;
        }
        super.freeData();
    }
}
